// pages/letRedpag/index.js
const app = getApp()
var page = 1;
var pagesize = 12;
var id = 1;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userBasic:{},
    redPackList:[],
    selected: true,
    selected1: false
  },

  selected: function (e) {
    id = e.currentTarget.id;
    this.setData({
      selected1: false,
      selected: true
    })
    this.onShow();
  },
  selected1: function (e) {
    id = e.currentTarget.id;
    this.setData({
      selected: false,
      selected1: true
    })
    this.onShow();
  },
  goShare: function (e) {
    var rid = e.currentTarget.id;
    wx.navigateTo({
      url: '../share/index?rid=' + rid,
    })
  },
  //获取个人基本信息
  getUserBasicInfo: function () {
    var that = this;
    var data = [];
    var url = 'We_Community/getBrowsePersonalUserBasic'
    var calkdata = app.netWorkRequest(that, data, url, 'userBasic')
  },
  //提取红包记录
  getReapackReceiveList:function(){
    var that = this;
    var data = [];
    data['type'] = id;
    data['page'] = page;
    data['pagesize'] = pagesize;
    var url = 'We_Redenvelopes/getRedenvelopeReceiveList';
    var calkdata = app.netWorkRequest(that, data, url, 'redPackList')
  },
  //加载更多红包记录
  getReapackReceiveListLoadMore: function () {
    console.log('椰树', page)
    console.log('类型', page)
    var that = this;
    var data = [];
    // 页数+1
    page = page + 1;
    data['type'] = id;
    data['page'] = page;
    data['pagesize'] = pagesize;
    var url = 'We_Redenvelopes/getRedenvelopeReceiveList';
    var f_data = that.data.redPackList;
    var calkdata = app.netWorkRequestLoadMore(that, data, url, 'redPackList', f_data);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('监听页面加载')
    id = 1;
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    console.log('监听页面初次渲染完成')
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log('监听页面显示',id)
    page = 1;
    this.getUserBasicInfo();
    this.getReapackReceiveList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    console.log('监听页面隐藏')
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    console.log('监听页面卸载')

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.onShow();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    wx.showLoading({
      title: '玩命加载中',
    })
    this.getReapackReceiveListLoadMore();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})